home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
idemo
/
idemo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-26
|
44KB
|
1,408 lines
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/*** idemo.c ***/
/*****************************************************************************
*
* INTUITION Test Suite
*
* =Robert J. Mical=
* 28 April 1985
* (created: 31 January 1985)
*
* At one time or another, this program has tested all of the INTUITION
* features, and sometimes has tested even the limits of my patience.
*
* CONFIDENTIAL and PROPRIETARY
* Copyright (C) 1985, COMMODORE-AMIGA, INC.
* All Rights Reserved
*
*
*****************************************************************************
*
* This program is not the neatest bit of code I've ever written.
* I'm a busy guy, you know? I do my best, especially considering that
* this is a rag-tag program that I've been using since the beginning to work
* out the INTUITION details, so it's grown by jerks and splats.
* This program is naughty. It reuses Requesters capriciously. It's a test
* program for INTUITION functionality, after all, not a polished work of
* software. Don't be surprised if things get fouled up should you try
* to do very convoluted things with this code. Make sure your own software
* is much more careful and consistent than the following code. =RJ=
*
*****************************************************************************
*
* NOTE: for a summary of all the commands you have available to you in this
* program, please refer to the file idemo.guide. All of the case statements
* are listed in that file, just for you!
*
****************************************************************************/
#include "idemoall.h"
#define SELECTUP (IECODE_LBUTTON | IECODE_UP_PREFIX)
#define SELECTDOWN IECODE_LBUTTON
#define MENUUP (IECODE_RBUTTON | IECODE_UP_PREFIX)
#define MENUDOWN IECODE_RBUTTON
#define HALFMILLION 500000
/* these produce an 8-1/2 wide dump on the Diablo C150 */
#define DUMP_WIDTH 1024
#define DUMP_HEIGHT 640
extern struct Menu menus[2][7]; /* defined in demomenu.c */
extern struct MenuItem items[]; /* defined in demomenu.c */
extern struct Menu IslandMenu; /* defined in demomenu2.c */
extern struct Requester TestRequest[]; /* defined in demoreq.c */
extern struct Gadget BoolGadget; /* defined in demoreq.c */
extern struct Gadget ReqProp; /* defined in demoreq.c */
struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;
UBYTE AlertString[] =
"\0\210\15ALERT: System Out of Memory Error\0\1\
\0\10\32Press Left Button to Retry\0\1\
\1\150\32Press Right Button to Abort\0\1\
\0\214\47Guru Meditation Number 0x87000005\0"; /* c puts the extra NULL */
UBYTE *AllocRaster();
struct Window *OpenWindow();
struct Screen *OpenScreen();
struct menuItem *ItemAddress();
UBYTE GetKey();
BOOL DisplayAlert();
USHORT red = 5; /* pseudo-random Screen colors */
USHORT green = 10; /* pseudo-random Screen colors */
USHORT blue = 15; /* pseudo-random Screen colors */
struct Window *RecentWindow; /* for anyone who wants the most recent */
struct Screen *StartupScreen;
SHORT screenindex;
UBYTE *ScreenTitles[] =
{
"A Matter of Intuition",
"=VoodooDrRj= Screen Title",
"Good Day, Ice Cream",
"Like These Colors Screen",
};
#include "../intuition/intuinternal.h"
struct IntuiText BodyText2 =
{
0, 1,
JAM2,
15, 25,
NULL,
" HEY! Pay Attention! ",
NULL,
};
struct IntuiText BodyText1 =
{
0, 1,
JAM2,
15, 10,
NULL,
"Body Text Line For You",
&BodyText2,
};
struct IntuiText GoodText =
{
AUTOFRONTPEN, AUTOBACKPEN,
AUTODRAWMODE,
AUTOLEFTEDGE, AUTOTOPEDGE,
AUTOITEXTFONT,
"Favorable",
AUTONEXTTEXT,
};
struct IntuiText BadText =
{
AUTOFRONTPEN, AUTOBACKPEN,
AUTODRAWMODE,
AUTOLEFTEDGE, AUTOTOPEDGE,
AUTOITEXTFONT,
"Unfavorable",
AUTONEXTTEXT,
};
/* ======================================================================== */
/* === Demo Toggle Gadget ================================================= */
/* ======================================================================== */
USHORT ToggleData[] =
{
0xFFFF, 0xF000,
0x5555, 0x5000,
0xFFFF, 0xF000,
0x5555, 0x5000,
0xFFFF, 0xF000,
0x5555, 0x5000,
0xFFFF, 0xF000,
0x5555, 0x5000,
0xFFFF, 0xF000,
0x5555, 0x5000,
};
struct Image ToggleImage =
{
0, 0, /* LeftEdge, TopEdge */
20, 10, 1, /* Width, Height, Depth */
ToggleData, /* ImageData */
0x2, 0x1, /* PlanePick, PlaneOnOff */
};
struct Gadget ToggleGadget =
{
NULL, /* Next Gadget */
20, 10, 20, 10, /* (Left Top Width Height */
GADGHBOX | SELECTED | GADGIMAGE, /* Flags */
GADGIMMEDIATE | RELVERIFY | TOGGLESELECT, /* Activation flags */
BOOLGADGET, /* Type */
&ToggleImage, /* Border Image */
NULL, /* no SelectRender */
NULL, /* no GadgetText */
0, /* no MutualExclude */
NULL, /* no SpecialInfo */
NULL, /* no ID */
NULL, /* no special data */
};
/* ======================================================================== */
/* === String Gadget ====================================================== */
/* ======================================================================== */
USHORT StrVectors[] =
{
0, 0,
208, 0,
208, 12,
0, 12,
0, 0,
207, 0,
207, 12,
1, 12,
1, 0,
};
struct Border StrBorder =
{
-4, -2, /* initial offsets */
1, 0, JAM1, /* pens and drawmode */
9, /* number of vectors */
StrVectors, /* pointer to the actual array of vectors */
NULL, /* next Border */
};
/*???#define STRINGSIZE 100*/
#define STRINGSIZE 5
/*???UBYTE StrBuffer[STRINGSIZE] = "String Gadgetry available now under Intuition";*/
UBYTE StrBuffer[STRINGSIZE] = "";
UBYTE UndoBuffer[STRINGSIZE];
struct StringInfo StrInfo =
{
StrBuffer, /* input buffer */
UndoBuffer, /* undo buffer */
0, /* buffer position */
STRINGSIZE, /* maximum number of chars, including trailing NULL */
0, 0, /* display, undo positions */
0, /* number of chars in the buffer */
0, 0, 0, /* position variables calculated by Intuition */
NULL, /* RastPort pointer */
NULL, /* LongInt */
};
struct IntuiText StrText =
{
1, 0,
JAM2,
55, 0,
NULL,
"DaveBTest",
NULL,
};
struct Gadget StringGadget =
{
NULL, /* Next Gadget */
10, 15, 201, 10, /* (Left Top (rel)Width Height */
GADGHCOMP, /* Flags */
/*??? LONGINT | STRINGCENTER | RELVERIFY, /* Activation flags */
STRINGRIGHT | RELVERIFY, /* Activation flags */
STRGADGET, /* Type */
&StrBorder, /* Border Image */
/*??? NULL, /* Border Image */
NULL, /* no SelectRender */
/*??? NULL, /* no GadgetText */
&StrText, /* no GadgetText */
0, /* no MutualExclude */
&StrInfo, /* SpecialInfo proportional data filled in later */
NULL, /* no ID */
NULL, /* no special data */
};
/* ======================================================================== */
/* === Proportional Gadgets in Window Borders ============================= */
/* ======================================================================== */
/* the following variables are used to create proportional Gadgets that
* will appear on the borders of opening Windows. These variables will
* be filled in with copies of the generic Gadgetry below
*/
SHORT PropCount; /* index to next available Gadget */
#define PROPMAX 20 /* maximum number of Gadgets */
struct Image PropImage[PROPMAX]; /* dummy AUTOKNOB Images */
struct Gadget Props[PROPMAX]; /* these get copies of PropGadget */
struct PropInfo PInfos[PROPMAX]; /* these get copies of TestProp */
/* this is the template for the PropInfo of a Proportional Gadget */
struct PropInfo TestPropInfo =
{
AUTOKNOB, /* Flags: has no FREEdom yet */
0, 0, /* Pots: both start at 0 */
0x5555, 0x3FFF, /* Bodies: Horiz is 1/3, Vert is 1/4 */
0, 0, 0, 0, 0, 0, /* System usage stuff */
};
/* this is the template for the Gadget of a vertical Proportional Gadget */
struct Gadget VPropGadget =
{
NULL, /* NextGadget */
-15, 10, 16, -9-10, /* (rel)Left Top Width (rel)Height */
GADGHCOMP | GADGIMAGE | GRELRIGHT | GRELHEIGHT, /* Flags */
GADGIMMEDIATE | RIGHTBORDER | RELVERIFY, /* Activation flags */
PROPGADGET, /* Type */
NULL, /* Image filled in later with dummy since this is AUTOKNOB */
NULL, /* no SelectRender */
NULL, /* no GadgetText */
0, /* no MutualExclude */
NULL, /* SpecialInfo proportional data filled in later */
NULL, /* no ID */
NULL, /* no special data */
};
/* this is the template for the Gadget of a horizontal Proportional Gadget */
struct Gadget HPropGadget =
{
NULL, /* NextGadget */
0, -8, -15, 9, /* Select Box Left (rel)Top (rel)Width Height */
GADGHCOMP | GADGIMAGE | GRELWIDTH | GRELBOTTOM, /* Flags */
GADGIMMEDIATE | BOTTOMBORDER | RELVERIFY, /* Activation flags */
PROPGADGET, /* Type */
NULL, /* Image filled in later since this is AUTOKNOB */
NULL, /* no SelectRender */
NULL, /* no GadgetText */
0, /* no MutualExclude */
NULL, /* SpecialInfo proportional data filled in later */
NULL, /* no ID */
NULL, /* no special data */
};
/* ======================================================================== */
/* ======================================================================== */
/* ======================================================================== */
/* my own little pointer */
#define POINTHEIGHT 9
#define POINTWIDTH 9
#define PXOFFSET -4
#define PYOFFSET -4
USHORT Pointer[] =
{
0x0000, 0x0000, /* one word each for position and control */
0xC180, 0x4100,
0x6380, 0xA280,
0x3700, 0x5500,
0x1600, 0x2200,
0x0000, 0x0000,
0x1600, 0x2200,
0x2300, 0x5500,
0x4180, 0xA280,
0x8080, 0x4100,
0x0000, 0x0000,
0x0000, 0x0000,
};
/* my own font descriptor */
struct TextAttr TestFont =
{
"topaz.font", /* Font Name */
/* by changing the font height between 8 and 9, you get 80-col and 64-col
* fonts respectively
*/
8, /* Font Height */
FS_NORMAL, /* Style */
FPF_ROMFONT, /* Preferences */
};
/* my own font descriptor */
struct TextAttr TopazSixty =
{
"topaz.font", /* Font Name */
/* by changing the font height between 8 and 9, you get 80-col and 64-col
* fonts respectively
*/
TOPAZ_SIXTY, /* Font Height */
FS_NORMAL, /* Style */
FPF_ROMFONT, /* Preferences */
};
/* ======================================================================== */
/* === Assorted Window Titles ============================================= */
/* ======================================================================== */
BYTE *WindowTitle[] =
{
"=>RJ<=",
" Test Window #347812678111",
"Normal Pens Window",
"BADOOLIE Breath",
"Your Own Window Specifications",
"From Here To Katmandu",
"Big City Word Processor",
};
/* ======================================================================== */
/* === General Purpose Window Task ======================================== */
/* ======================================================================== */
windowtask(screen)
struct Screen *screen;
/* The windowtask starts out by opening a Window of your design. It can
* then accept input from the IDCMP, depending on your preferences
* The screen arg can either point to a CUSTOM SCREEN or be NULL (which
* means we're still under WorkBench)
*/
{
SHORT top, left, width, height, windownum, detailpen, blockpen;
ULONG flags, idcmp;
struct Window *w;
SHORT pointer;
BOOL vprop, hprop;
struct IntuiMessage *message;
SHORT toll;
struct Gadget *newgadgets;
struct NewWindow NewWindow;
UBYTE *title;
struct Task *task;
task = (struct Task *)FindTask(0);
printf("***New Task: lower=%lx current=%lx upper=%lx\n",
task->tc_SPLower, &task, task->tc_SPUpper);
printf("OPENING A WINDOW:\n");
printf(" Select a Window Preset number (or 'x' to create your own) : ");
windownum = GetNum();
printf("\n");
switch (windownum)
{
case 0:
left = 10;
top = 84;
width = 200;
height = 59;
detailpen = 3;
blockpen = 2;
title = WindowTitle[windownum];
flags = GIMMEZEROZERO | WINDOWDEPTH | WINDOWSIZING
| WINDOWDRAG | WINDOWCLOSE | SMART_REFRESH;
idcmp = RAWKEY | CLOSEWINDOW | MOUSEMOVE | MENUVERIFY
| NEWPREFS;
hprop = TRUE;
vprop = TRUE;
break;
case 1:
left = 65;
top = 53;
width = 200;
height = 128;
detailpen = 0;
blockpen = 2;
title = WindowTitle[windownum];
flags = ACTIVATE | WINDOWDEPTH | WINDOWSIZING
| WINDOWDRAG | WINDOWCLOSE | SIMPLE_REFRESH;
idcmp = RAWKEY | MOUSEBUTTONS | MOUSEMOVE | GADGETDOWN
| GADGETUP | MENUPICK | CLOSEWINDOW
| SIZEVERIFY | NEWSIZE | MENUVERIFY
| NEWPREFS;
hprop = FALSE;
vprop = TRUE;
break;
case 2:
left = 0;
top = 5;
/*??? top = 25;*/
width = 320;
height = 150;
detailpen = 0;
blockpen = 1;
title = WindowTitle[windownum];
flags = WINDOWDEPTH | WINDOWDRAG | WINDOWSIZING | WINDOWCLOSE
| BACKDROP | SMART_REFRESH;
idcmp = MENUPICK | CLOSEWINDOW | MENUVERIFY
| NEWPREFS;
hprop = TRUE;
vprop = FALSE;
break;
case 3:
left = 0;
top = 10;
width = 300;
height = 90;
detailpen = -1;
blockpen = -1;
title = WindowTitle[windownum];
flags = ACTIVATE | WINDOWDRAG | SMART_REFRESH;
idcmp = GADGETUP | MENUVERIFY
| NEWPREFS;
hprop = FALSE;
vprop = FALSE;
break;
case 4:
left = 0;
top = 0;
if (screen) width = 320;
else width = 640;
height = 200;
detailpen = -1;
blockpen = -1;
title = NULL;
flags = BACKDROP | SIMPLE_REFRESH;
idcmp = GADGETDOWN | GADGETUP | MENUVERIFY
| REQVERIFY | RAWKEY
| NEWPREFS;
hprop = FALSE;
vprop = FALSE;
break;
case 5:
left = 100;
top = 100;
width = 220;
height = 100;
detailpen = 2;
blockpen = 3;
title = WindowTitle[windownum];
flags = SMART_REFRESH | RMBTRAP
| WINDOWDEPTH | WINDOWSIZING
| WINDOWDRAG | WINDOWCLOSE;
idcmp = GADGETDOWN | GADGETUP
| RAWKEY | REFRESHWINDOW
| NEWPREFS | MOUSEBUTTONS | CLOSEWINDOW;
hprop = FALSE;
vprop = FALSE;
break;
case 6:
left = 100;
top = 100;
width = 220;
height = 100;
detailpen = -1;
blockpen = -1;
title = WindowTitle[windownum];
flags = SMART_REFRESH
| WINDOWDEPTH | WINDOWSIZING
| WINDOWDRAG | WINDOWCLOSE;
idcmp = GADGETDOWN | GADGETUP
| RAWKEY | REFRESHWINDOW
| NEWPREFS | MOUSEBUTTONS | CLOSEWINDOW;
hprop = TRUE;
vprop = TRUE;
break;
case 8:
left = 10;
top = 84;
width = 200;
height = 59;
detailpen = -1;
blockpen = -1;
title = WindowTitle[0];
flags = GIMMEZEROZERO | WINDOWDEPTH | WINDOWSIZING
| WINDOWDRAG | WINDOWCLOSE | SMART_REFRESH;
idcmp = RAWKEY | CLOSEWINDOW | MOUSEMOVE | MENUVERIFY
| NEWPREFS;
hprop = TRUE;
vprop = TRUE;
break;
default:
windownum = 6;
printf("\n left = ");
left = GetNum();
printf("\n top = ");
top = GetNum();
printf("\n width = ");
width = GetNum();
printf("\n height = ");
height = GetNum();
printf("\n detailpen = ");
detailpen = GetNum();
printf("\n blockpen = ");
blockpen = GetNum();
printf("\n flags = ");
flags = GetNum();
printf("\n idcmp = ");
idcmp = GetNum();
printf("\n horizontal prop gadget = ");
hprop = GetNum();
printf("\n vertical prop gadget = ");
vprop = GetNum();
break;
}
newgadgets = NULL;
if (vprop)
{
if (flags & WINDOWSIZING) flags |= SIZEBBOTTOM;
Props[PropCount] = VPropGadget;
PInfos[PropCount] = TestPropInfo;
PInfos[PropCount].Flags |= FREEVERT;
Props[PropCount].GadgetRender = &PropImage[PropCount];
Props[PropCount].SpecialInfo = &PInfos[PropCount];
newgadgets = &Props[PropCount++];
}
if (hprop)
{
if (flags & WINDOWSIZING) flags |= SIZEBRIGHT;
Props[PropCount] = HPropGadget;
if ((windownum == 0) || (windownum == 8))
Props[PropCount].GadgetType |= GZZGADGET;
PInfos[PropCount] = TestPropInfo;
PInfos[PropCount].Flags |= FREEHORIZ;
Props[PropCount].GadgetRender = &PropImage[PropCount];
Props[PropCount].SpecialInfo = &PInfos[PropCount];
if (newgadgets) newgadgets->NextGadget = &Props[PropCount++];
else newgadgets = &Props[PropCount++];
}
if (windownum == 1)
{
/*???printf("%ToggleGadget=%lx\n",&ToggleGadget);*/
/*??? if (newgadgets) newgadgets->NextGadget = &ToggleGadget;*/
/*??? else newgadgets = &ToggleGadget;*/
}
if (windownum == 3)
{
if (newgadgets) newgadgets->NextGadget = &StringGadget;
else newgadgets = &StringGadget;
printf("&Activation=%lx\n",&StringGadget.Activation);
}
NewWindow.LeftEdge = left;
NewWindow.TopEdge = top;
NewWindow.Width = width;
NewWindow.Height = height;
NewWindow.DetailPen = detailpen;
NewWindow.BlockPen = blockpen;
NewWindow.Title = title;
NewWindow.Flags = flags;
NewWindow.IDCMPFlags = idcmp;
if (screen) NewWindow.Type = CUSTOMSCREEN;
else NewWindow.Type = WBENCHSCREEN;
NewWindow.FirstGadget = newgadgets;
NewWindow.CheckMark = NULL;
NewWindow.Screen = screen;
NewWindow.BitMap = NULL;
NewWindow.MinWidth = width - 20;
NewWindow.MinHeight = height - 20;
NewWindow.MaxWidth = width + 20;
NewWindow.MaxHeight = height + 20;
if ((windownum <= 0) || (windownum >= 5))
{
NewWindow.MinHeight = height;
NewWindow.MaxWidth = 32767;
NewWindow.MaxHeight = 32767;
}
if ((w = OpenWindow(&NewWindow)) == NULL)
{
printf("\nMAYDAY MAYDAY: couldn't open that Window!\n");
RemTask(0);
}
printf("Your Window structure is at location %lx\n", w);
RecentWindow = w; /* assign it to the global variable */
if (windownum != 6) SetMenuStrip(w, &menus[windownum & 1][0]);
else SetMenuStrip(w, &menus[1][0]);
/*??? if (windownum) SetDMRequest(w, &TestRequest[1 - (windownum & 1)]);*/
SetDMRequest(w, &TestRequest[1 - (windownum & 1)]);
if (windownum == 1)
SetPointer(w, Pointer, POINTHEIGHT, POINTWIDTH, PXOFFSET, PYOFFSET);
toll = 3;
/* now hang around waiting for news on the IDCMP */
FOREVER
{
Wait(1 << w->UserPort->mp_SigBit);
while (message = (struct IntuiMessage *)GetMsg(w->UserPort))
{
printf("message=%lx Class=%lx Code=%lx X=%ld Y=%ld\n",
message, message->Class, message->Code,
message->MouseX, message->MouseY);
switch (message->Class)
{
case REFRESHWINDOW:
printf("REFRESHWINDOW=%lx\n", w);
BeginRefresh(w);
EndRefresh(w, TRUE);
break;
case RAWKEY: getansi(message, w); break;
case GADGETUP: gadgetmessage(message, w); break;
case SIZEVERIFY: sizeverify(message, w); break;
case NEWSIZE: newsize(message, w); break;
case REQVERIFY: dmreqverify(message, w); break;
case MENUVERIFY: menuverify(windownum, message, w); break;
case MENUPICK: setmenus(message, w); break;
case MOUSEBUTTONS: mousebuttons(message, w); break;
case CLOSEWINDOW:
if ((toll = closewindow(message, w, toll)) == 0)
{
if (screen) if (screen->FirstWindow == NULL)
{
printf("trying to close Screen %lx ", screen);
CloseScreen(screen);
printf("and succeeding!\n");
}
/* that's it, time to exit this Window task */
/* this is naughty, it should free its stack */
RemTask(0);
}
/* else, we still continue on */
break;
default: ReplyMsg(message); break;
}
}
}
}
mousebuttons(message, w)
struct IntuiMessage *message;
struct Window *w;
{
switch (message->Code)
{
case MENUDOWN: printf("MENUDOWN received\n"); break;
case MENUUP: printf("MENUUP received\n"); break;
case SELECTDOWN: printf("SELECTDOWN received\n"); break;
case SELECTUP: printf("SELECTUP received\n"); break;
default: printf("WEIRD %lx received\n",message->Code); break;
}
ReplyMsg(message);
}
menuverify(windownum, message, w)
USHORT windownum;
struct IntuiMessage *message;
struct Window *w;
{
if (message->Code == MENUHOT)
{
/* this one must be the active Window
* set it only for Window 0, which requires the Pointer to
* be at or above the Screen Title Bar
*/
if ((windownum == 0) && (w->WScreen->MouseY > 10))
message->Code = MENUCANCEL;
}
ReplyMsg(message);
}
gadgetmessage(message, w)
struct IntuiMessage *message;
struct Window *w;
{
struct Gadget *g;
printf("GADGETUP GOTTEN, for Gadget at %lx\n",message->IAddress);
g = (struct Gadget *)message->IAddress;
if (g->Activation & LONGINT)
{
printf(" LONGINT with value = %ld\n",
(LONG)((struct StringInfo *)g->SpecialInfo)->LongInt);
}
ReplyMsg(message);
}
getansi(message, w)
struct IntuiMessage *message;
struct Window *w;
{
UBYTE character;
USHORT pen, rgb, red, green, blue;
struct Preferences prefs;
if (character = GetKey(message))
printf("%lc", character);
ReplyMsg(message);
switch (character)
{
case 'a':
RemoveGadget(w, &ToggleGadget);
RefreshGadgets(w->FirstGadget, w);
if (ToggleGadget.Flags & SELECTED)ToggleGadget.Flags &= ~SELECTED;
else ToggleGadget.Flags |= SELECTED;
break;
case 'A':
AddGadget(w, &ToggleGadget, -1);
RefreshGadgets(w->FirstGadget, w);
break;
case 'c':
printf("What pen number: "); pen = GetNum();
rgb = GetRGB4(w->WScreen->ViewPort.ColorMap, pen);
red = (rgb >> 8) & 0xF;
green = (rgb >> 4) & 0xF;
blue = (rgb) & 0xF;
printf("\nRed=%ld. What value for red: ", red);
red = GetNum();
printf("\nGreen=%ld. What value for green: ", green);
green = GetNum();
printf("\nBlue=%ld. What value for blue: ", blue);
blue = GetNum();
SetRGB4(&w->WScreen->ViewPort, pen, red, green, blue);
break;
case 'i':
case 'I':
TestITLength();
case 'p':
case 'P':
GetDefPrefs(&prefs, sizeof(struct Preferences));
printf("&prefs=%lx\n",&prefs);
Debug();
break;
case 'R':
Request(&TestRequest[2], w);
break;
case 's':
ShowTitle(w->WScreen, FALSE);
break;
case 'S':
ShowTitle(w->WScreen, TRUE);
break;
case 'T':
SetWindowTitles(w, "Here's a new Window Title",
"The Big-T Screen Title");
break;
case 't':
SetWindowTitles(w, -1, "The little-t Screen Title");
break;
case 'w':
WindowToBack(w);
break;
case 'W':
WindowToFront(w);
break;
case 'x':
SizeWindow(w, -2, 0);
break;
case 'X':
SizeWindow(w, 2, 0);
break;
case 'y':
SizeWindow(w, 0, -1);
break;
case 'Y':
SizeWindow(w, 0, 1);
break;
case '1':
WBenchToBack();
break;
case '!':
WBenchToFront();
break;
case '-':
MoveWindow(w, -2, 0);
break;
case '_':
MoveWindow(w, 2, 0);
break;
case '=':
MoveWindow(w, 0, -1);
break;
case '+':
MoveWindow(w, 0, 1);
break;
}
}
TestITLength()
{
struct IntuiText itext;
itext.ITextFont = NULL;
itext.IText = "=VoodooDrRj=";
printf("Pixel width with default font is %ld\n", IntuiTextLength(&itext));
itext.ITextFont = &TestFont;
printf("Pixel width with TestFont is %ld\n", IntuiTextLength(&itext));
itext.IText = "";
printf("Pixel width with null string is %ld\n", IntuiTextLength(&itext));
}
setmenus(message, w)
struct IntuiMessage *message;
struct Window *w;
{
struct Menu *menu;
struct MenuItem *nextitem, *subitem;
USHORT nextnum;
if ((nextnum = message->Code) == MENUNULL) return;
nextitem = ItemAddress(w->MenuStrip, nextnum);
do
{
printf("*** Menu=%ld Item=%ld Sub=%ld\n",
MENUNUM(nextnum), ITEMNUM(nextnum), SUBNUM(nextnum));
setMenuGrunt(nextitem, nextnum, w);
nextnum = nextitem->NextSelect;
nextitem = ItemAddress(w->MenuStrip, nextnum);
}
while (nextitem);
/* now check if all are turned off yet, and if so turn them all on */
/* if I find an enabled item anywhere, return immediately */
/* if I make it to the end, all items are disabled */
menu = w->MenuStrip;
do
{
nextitem = menu->FirstItem;
while (nextitem)
{
if (subitem = nextitem->SubItem)
{
while (subitem)
{
if (subitem->Flags & ITEMENABLED) return;
subitem = subitem->NextItem;
}
}
else /* there's no subitems, so check this item itself */
if (nextitem->Flags & ITEMENABLED) return;
nextitem = nextitem->NextItem;
}
menu = menu->NextMenu;
}
while(menu);
printf("OK, all items disabled. Enabling everyone now ... ");
menu = w->MenuStrip;
do
{
menu->Flags |= MENUENABLED;
nextitem = menu->FirstItem;
while (nextitem)
{
if (subitem = nextitem->SubItem)
{
while (subitem)
{
subitem->Flags |= ITEMENABLED;
subitem = subitem->NextItem;
}
}
else /* there's no subitems, so check this item itself */
nextitem->Flags |= ITEMENABLED;
nextitem = nextitem->NextItem;
}
menu = menu->NextMenu;
}
while(menu);
printf("done!\n");
}
setMenuGrunt(item, menunum, w)
struct MenuItem *item;
USHORT menunum;
struct Window *w;
{
/* now, item points to the MenuItem that we want to disable */
if ((item->Flags & ITEMENABLED) == NULL)
{
printf("Hey, that item was disabled! How did that happen?\n");
Debug();
}
OffMenu(w, menunum);
}
dmreqverify(message, w)
struct IntuiMessage *message;
struct Window *w;
{
SHORT count;
printf("REQ? Well...");
for (count = 65535; count; count--) ;
printf("well...");
for (count = 65535; count; count--) ;
printf("well...");
for (count = 65535; count; count--) ;
printf("well...");
for (count = 65535; count; count--) ;
printf("OK!\n");
ReplyMsg(message);
}
newsize(message, w)
struct IntuiMessage *message;
struct Window *w;
{
Move(w->RPort, 20, 10);
Draw(w->RPort, 110, 100);
}
SHORT pen = 0;
sizeverify(message, w)
struct IntuiMessage *message;
struct Window *w;
{
SHORT count;
SetAPen(w->RPort, pen++);
Move(w->RPort, 10, 10);
Draw(w->RPort, 100, 100);
printf("SIZE? Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("OK!\n");
ReplyMsg(message);
/*???return;*/
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("Hmm...");
for (count = 65535; count; count--) ;
printf("OK!\n");
Request(&TestRequest[2], w);
}
SHORT closewindow(message, window, count)
struct IntuiMessage *message;
struct Window *window;
SHORT count;
{
switch (--count)
{
case 2:
printf("are you sure you want to die? I'll reply this time.\n");
ReplyMsg(message);
return(count);
break;
case 1:
printf("are you really really sure?\n");
ReplyMsg(message);
return(count);
break;
default:
/* very bad of me. I didn't Reply() to last the last message */
printf("bye now.\n");
ReplyMsg(message);
CloseWindow(window);
return(0);
}
}
rjopenwindow(screen)
struct Screen *screen;
/* if the screen arg == NULL, this is still WorkBench */
{
struct Task *task;
SHORT i;
LONG *stack;
BYTE *aptr;
if ((task = (struct Task *)AllocMem(sizeof(struct Task),
MEMF_CLEAR | MEMF_PUBLIC)) == 0)
Panic("task alloc out of mem!");
if ((stack = (LONG *)AllocMem(sizeof(LONG) * 1024, MEMF_CLEAR)) == 0)
Panic("stack alloc out of mem!");
/*??? task->tc_Node.ln_Pri = 0;*/
task->tc_Node.ln_Pri = 5;
task->tc_SPReg = &stack[1023];
task->tc_SPLower = stack;
task->tc_SPUpper = &stack[1023];
task->tc_Node.ln_Name = "WindowTask";
/* pass the screen address as an argument to the procedure */
stack[1023] = (LONG)screen;
AddTask(task, windowtask, 0);
}
struct Screen *rjopenscreen()
{
SHORT depth, lace;
struct Screen *screen;
struct NewScreen NewScreen;
printf("about to open a LowRes Screen. What depth should I use: ");
depth = GetNum();
printf("Want INTERLACE : "); lace = GetNum();
NewScreen.LeftEdge = 0;
NewScreen.TopEdge = 0;
NewScreen.Width = 320;
NewScreen.Depth = depth;
NewScreen.Type = CUSTOMSCREEN;
NewScreen.DetailPen = 1;
NewScreen.BlockPen = 3;
NewScreen.DefaultTitle = ScreenTitles[(screenindex++) & 0x3];
if (lace)
{
NewScreen.ViewModes = INTERLACE;
NewScreen.Height = 400;
}
else
{
NewScreen.ViewModes = NULL;
NewScreen.Height = 200;
}
NewScreen.Font = &TestFont;
NewScreen.Gadgets = NULL;
screen = OpenScreen(&NewScreen);
SetRGB4(&screen->ViewPort, 0, red++, green++, blue++);
SetRGB4(&screen->ViewPort, 1, 15, 15, 15);
SetRGB4(&screen->ViewPort, 2, blue, red, green);
SetRGB4(&screen->ViewPort, 3, green, blue, red);
blue++;
green = (green + blue) & 0xF;
red = (green + blue + red) & 0xF;
return(screen);
}
struct Screen *autoopenscreen()
{
SHORT depth, lace;
struct Screen *screen;
struct NewScreen NewScreen;
depth = 3;
NewScreen.LeftEdge = 0;
NewScreen.TopEdge = 0;
NewScreen.Width = 640;
NewScreen.Depth = depth;
NewScreen.Type = CUSTOMSCREEN;
NewScreen.DetailPen = 1;
NewScreen.BlockPen = 3;
NewScreen.DefaultTitle = ScreenTitles[(screenindex++) & 0x3];
NewScreen.ViewModes = HIRES;
NewScreen.Height = 200;
NewScreen.Font = &TestFont;
NewScreen.Gadgets = NULL;
screen = OpenScreen(&NewScreen);
SetRGB4(&screen->ViewPort, 0, red++, green++, blue++);
SetRGB4(&screen->ViewPort, 1, 15, 15, 15);
SetRGB4(&screen->ViewPort, 2, blue, red, green);
SetRGB4(&screen->ViewPort, 3, green, blue, red);
blue++;
green = (green + blue) & 0xF;
red = (green + blue + red) & 0xF;
return(screen);
}
main()
{
/* ==========================================================================
* === OK, here's the real program! =========================================
* ==========================================================================
*/
struct Screen *workscreen;
SHORT time, c, i, i2, error, dumpwidth, dumpheight;
LONG longi;
struct Window *w;
struct RastPort *rp;
ULONG Seconds, Micros;
struct Preferences Prefs;
struct View *View;
struct ViewPort *vp;
if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)) == 0)
Panic("Woah, no graphics library in main!");
if ((IntuitionBase = (LONG *)OpenLibrary("intuition.library", 0)) == 0)
Panic("Woah, no intuition library in main!");
time = 0;
workscreen = NULL;
PropCount = 0;
printf("&IBase->ActiveWindow=%lx\n",&IntuitionBase->ActiveWindow);
printf("sizeof(IBase)=%lx\n", sizeof(struct IntuitionBase));
printf("sizeof(Preferences)=%lx\n", sizeof(struct Preferences));
printf("sizeof(IntuiMessage)=%lx\n", sizeof(struct IntuiMessage));
printf("&ReqProp=%lx\n",&ReqProp);
StartupScreen = workscreen = IntuitionBase->ActiveScreen;
RecentWindow = IntuitionBase->ActiveWindow;
dumpwidth = DUMP_WIDTH;
dumpheight = DUMP_HEIGHT;
RESTART:
while ((c = MayGetChar()) == -1) ;
switch (c)
{
case 'A':
i = AutoRequest(RecentWindow, &BodyText1, &GoodText, &BadText,
DISKINSERTED, NULL, 320, 100);
printf("Result of AutoRequest()=%lx\n", i);
break;
case 'b':
MoveScreen(workscreen, 0, -2);
break;
case 'B':
MoveScreen(workscreen, 0, 2);
break;
case 'c': /* 'c' for crazy screen, to prove microsoft wrong */
i = 0;
while ((c = MayGetChar()) == -1)
{
workscreen = autoopenscreen(workscreen);
i++;
printf("\nscreen %ld: press any key to quit:", i);
for (longi = 0; longi < HALFMILLION; longi++) ;
CloseScreen(workscreen);
}
break;
case 'd':
Debug();
break;
case 'D':
printf("&AlertString=%lx\n",&AlertString[0]);
DisplayAlert(RECOVERY_ALERT, AlertString, 49);
break;
case 'e':
printf("Leaving now! Bye.\n");
exit(TRUE);
case 'p':
/* print the active window */
error = PrinterOpen(AllocSignal(-1));
if (error)
{
printf("Open Printer error=%ld\n", error);
break;
}
workscreen = IntuitionBase->ActiveScreen;
RecentWindow = IntuitionBase->ActiveWindow;
vp = &workscreen->ViewPort;
longi = (RecentWindow->Width << 16) / RecentWindow->Height;
i = (dumpwidth * longi) >> 16;
error = PrintRPort(RecentWindow->RPort,
vp->ColorMap, vp->Modes,
0, 0,
RecentWindow->Width, RecentWindow->Height,
/*??? dumpwidth, i, */
dumpwidth, dumpheight,
0);
if (error) printf("The DUMP error # is %ld\n",error);
PrinterClose();
break;
case 'P':
/* print the active screen */
error = PrinterOpen(AllocSignal(-1));
if (error)
{
printf("Open Printer error=%ld\n", error);
break;
}
workscreen = IntuitionBase->ActiveScreen;
vp = &workscreen->ViewPort;
printf("Short=0, Long=1:");
i = GetNum();
printf("\n");
if (i)
error = PrintRPort(&workscreen->RastPort,
workscreen->ViewPort.ColorMap,
workscreen->ViewPort.Modes,
0, 0,
workscreen->Width, workscreen->Height,
dumpwidth, dumpheight, 0);
else
error = PrintRPort(&workscreen->RastPort,
workscreen->ViewPort.ColorMap,
workscreen->ViewPort.Modes,
0, 0,
workscreen->Width, workscreen->Height / 4,
dumpwidth, dumpheight / 4, 0);
if (error) printf("The DUMP error # is %ld\n",error);
PrinterClose();
break;
case 'q':
Debug();
break;
case 's':
workscreen = rjopenscreen(workscreen);
break;
case 'S':
if (workscreen)
{
CloseScreen(workscreen);
workscreen = NULL;
}
else printf("No Screen opened yet!\n");
break;
case 't':
TestITLength();
break;
case 'T':
CurrentTime(&Seconds, &Micros);
printf("what are you waiting for? Seconds=%ld Micros=%ld\n",
Seconds, Micros);
break;
case 'v':
printf("CloseWorkBench()=%lx\n", CloseWorkBench());
break;
case 'V':
printf("OpenWorkBench()=%lx\n", OpenWorkBench());
break;
case 'w':
rjopenwindow(workscreen);
break;
case 'W':
printf("0=8.5, 1=7.5, 2=6.5, 3=5.5, 4=4.5, other=select: ");
i = GetNum();
switch (i)
{
case 0:
dumpwidth = 1024;
dumpheight = 640;
break;
case 1:
dumpwidth = 904;
dumpheight = 565;
break;
case 2:
dumpwidth = 783;
dumpheight = 489;
break;
case 3:
dumpwidth = 663;
dumpheight = 414;
break;
case 4:
dumpwidth = 542;
dumpheight = 339;
break;
default:
printf("\nwidth:"); dumpwidth = GetNum();
printf("\nheight:"); dumpheight = GetNum();
break;
}
printf("\n");
break;
case 'x':
DisplayBeep(NULL);
break;
case 'z':
View = (struct View *)ViewAddress();
printf("DxOffset=%ld DyOffset=%ld\n",
View->DxOffset, View->DyOffset);
break;
break;
default:
break;
}
goto RESTART;
}